package com.chif.goingplus.service;

import com.chif.goingplus.dao.BusMapper;
import com.chif.goingplus.dao.ClientMapper;
import com.chif.goingplus.dao.EmpMapper;
import com.chif.goingplus.dao.OrderMapper;
import com.chif.goingplus.pojo.*;
import com.chif.goingplus.utils.ChartMapperUtils;
import com.chif.goingplus.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EChartServiceImpl implements EChartService{
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private BusMapper busMapper;

    @Override
    public String getTrendData() {

        Trends trends = new Trends();

        //封装客源趋势图
        Trend<PosMonth> orgMonthTrend = ChartMapperUtils.getOrgMonthTrend();
        trends.setOriginTrend(orgMonthTrend);

        //封装去向趋势图
        Trend<PosMonth> disMonthTrend = ChartMapperUtils.getDisMonthTrend();
        trends.setDestinationTrend(disMonthTrend);

        //封装通用数据
        trends.setCommon(new Common());

        //封装下拉框的数据
        List<SelectType> selectTypes = new ArrayList();
        selectTypes.add(new SelectType("originTrend","客源分析趋势"));
        selectTypes.add(new SelectType("destinationTrend","去向分析趋势"));
        trends.setType(selectTypes);

        //返回所有趋势图
        return JsonUtils.getJson(trends);
    }

    @Override
    public String getRankData() {
        List<RegionOrder> regionOrder = orderMapper.getRegionOrder();
        return JsonUtils.getJson(regionOrder);
    }

    @Override
    public String getHotData() {
        List<Hots> hots = new ArrayList<>();

        //封装地区销量占比图数据
        List<RegionOrder> regionOrder = orderMapper.getRegionOrder();
        hots.add(new Hots("地区销量",regionOrder));

        //封装出发时间占比图数据
        List<Hot> beginTimeOrder = orderMapper.getBeginTimeOrder();
        hots.add(new Hots("出发时间",beginTimeOrder));


        //封装售票员
        List<SellerOrder> sellerOrders = orderMapper.querySellerOrder();
        hots.add(new Hots("售票员业绩",sellerOrders));

        //封装客源分析
        List<OriginOrder> originOrder = orderMapper.getOriginOrder();
        hots.add(new Hots("客源分析",originOrder));

        return JsonUtils.getJson(hots);
    }

    @Override
    public String getStockData() {
        List<Stock> stocks = busMapper.queryAllLoad();
        return JsonUtils.getJson(stocks);
    }

    @Override
    public String getMapData() {
        //返回客源坐标信息
        return "[\n" +
                "    {\n" +
                "        \"name\": \"黄金用户\",\n" +
                "        \"children\": [\n" +
                "            {\n" +
                "                \"name\": \"武汉\",\n" +
                "                \"value\": [114.31, 30.52]\n" +
                "            }, {\n" +
                "                \"name\": \"丹东\",\n" +
                "                \"value\": [124.37, 40.13]\n" +
                "            }, {\n" +
                "                \"name\": \"张家口\",\n" +
                "                \"value\": [114.87, 40.82]\n" +
                "            }, {\n" +
                "                \"name\": \"深圳\",\n" +
                "                \"value\": [114.07, 22.62]\n" +
                "            }\n" +
                "        ]\n" +
                "    },\n" +
                "    {\n" +
                "        \"name\": \"白金用户\",\n" +
                "        \"children\": [\n" +
                "            {\n" +
                "                \"name\": \"金华\",\n" +
                "                \"value\": [119.64, 29.12]\n" +
                "            }, {\n" +
                "                \"name\": \"西安\",\n" +
                "                \"value\": [108.95, 34.27]\n" +
                "            }\n" +
                "        ]\n" +
                "    },\n" +
                "    {\n" +
                "        \"name\": \"砖石用户\",\n" +
                "        \"children\": [\n" +
                "            {\n" +
                "                \"name\": \"成都\",\n" +
                "                \"value\": [104.06, 30.67]\n" +
                "            }\n" +
                "        ]\n" +
                "    }\n" +
                "]";
    }

    @Override
    public String getOrderAndIncomeCount() {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(orderMapper.getAllOrderCount());
        list.add(orderMapper.getCostCount());
        return JsonUtils.getJson(list);
    }

    @Override
    public String getSellerOrder() {
        return JsonUtils.getJson(orderMapper.querySellerOrder());
    }

    @Override
    public String getNewOrder(String orderInfo) {
        return null;
    }


}
